From fe92d1094cb453f3ea703d43223a83c802f92498 Mon Sep 17 00:00:00 2001 From: robertl Date: Wed, 2 Feb 2005 18:04:09 +0000 Subject: [PATCH] Fix a number of minor GPX issues: Fix order of creation time in output. Write desc and url in trackpoints. Abstract code for link writing. --- gpsbabel/gpx.c | 74 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index 31dc3e42b..c59db63db 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -62,6 +62,16 @@ static route_head *rte_head; #define MY_CBUF 4096 #define DEFAULT_XSI_SCHEMA_LOC "http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd" +/* + * Format used for floating point formats. Put in one place to make it + * easier to tweak when comparing output with other GPX programs that + * have more or less digits of output... + */ +/* #define FLT_FMT "%.9lf" */ /* ExpertGPS */ +#define FLT_FMT "%0.9lf" +#define FLT_FMT_T "%lf" +#define FLT_FMT_R "%lf" + typedef enum { tt_unknown = 0, tt_gpx, @@ -1075,6 +1085,33 @@ void free_gpx_extras( xml_tag *tag ) } } +/* + * Handle the grossness of GPX 1.0 vs. 1.1 handling of linky links. + */ +static void +write_gpx_url(const waypoint *waypointp) +{ + char *tmp_ent; + + if (waypointp->url) { + tmp_ent = xml_entitize(waypointp->url); + if (gpx_wversion_num > 10) { + + fprintf(ofd, " \n", + urlbase ? urlbase : "", tmp_ent); + write_optional_xml_entity(ofd, " ", "text", + waypointp->url_link_text); + fprintf(ofd, " \n"); + } else { + fprintf(ofd, " %s%s\n", + urlbase ? urlbase : "", tmp_ent); + write_optional_xml_entity(ofd, " ", "urlname", + waypointp->url_link_text); + } + xfree(tmp_ent); + } +} + static void gpx_waypt_pr(const waypoint *waypointp) { @@ -1097,35 +1134,24 @@ gpx_waypt_pr(const waypoint *waypointp) mkshort(mkshort_handle, odesc) : waypointp->shortname; - fprintf(ofd, "\n", + fprintf(ofd, "\n", waypointp->latitude, waypointp->longitude); - if (waypointp->creation_time) { - xml_write_time(ofd, waypointp->creation_time, "time"); - } if (waypointp->altitude != unknown_alt) { fprintf(ofd, " %f\n", waypointp->altitude); } + if (waypointp->creation_time) { + xml_write_time(ofd, waypointp->creation_time, "time"); + } write_optional_xml_entity(ofd, " ", "name", oname); write_optional_xml_entity(ofd, " ", "cmt", waypointp->description); if (waypointp->notes && waypointp->notes[0]) write_xml_entity(ofd, " ", "desc", waypointp->notes); else write_optional_xml_entity(ofd, " ", "desc", waypointp->description); - if (waypointp->url) { - tmp_ent = xml_entitize(waypointp->url); - if (gpx_wversion_num > 10) { - - fprintf(ofd, " \n", urlbase ? urlbase : "", tmp_ent); - write_optional_xml_entity(ofd, " ", "text", waypointp->url_link_text); - fprintf(ofd, " \n"); - } else { - fprintf(ofd, " %s%s\n", urlbase ? urlbase : "", tmp_ent); - write_optional_xml_entity(ofd, " ", "urlname", waypointp->url_link_text); - } - xfree(tmp_ent); - } + write_gpx_url(waypointp); + write_optional_xml_entity(ofd, " ", "sym", waypointp->icon_descr); fprint_xml_chain( waypointp->gpx_extras, waypointp ); @@ -1147,7 +1173,7 @@ gpx_track_hdr(const route_head *rte) static void gpx_track_disp(const waypoint *waypointp) { - fprintf(ofd, "\n", + fprintf(ofd, "\n", waypointp->latitude, waypointp->longitude); if (waypointp->altitude != unknown_alt) { @@ -1157,6 +1183,16 @@ gpx_track_disp(const waypoint *waypointp) if (waypointp->creation_time) { xml_write_time(ofd, waypointp->creation_time,"time"); } + + /* GPX doesn't require a name on output, so if we made one up + * on input, we might as well say nothing. + */ + if (!waypointp->shortname_is_synthetic) { + write_optional_xml_entity(ofd, " ", "name", + waypointp->shortname); + } + write_optional_xml_entity(ofd, " ", "desc", waypointp->notes); + write_gpx_url(waypointp); write_optional_xml_entity(ofd, " ", "sym", waypointp->icon_descr); fprintf(ofd, "\n"); } @@ -1188,7 +1224,7 @@ gpx_route_hdr(const route_head *rte) static void gpx_route_disp(const waypoint *waypointp) { - fprintf(ofd, " \n", + fprintf(ofd, " \n", waypointp->latitude, waypointp->longitude); -- 2.30.2